import datetime
from django.contrib import admin

from .models import User,Category,Product,Comment,Cart,Item,Address,Express,Pay,Order
# Register your models here.

class ProductInline(admin.TabularInline):
    model = Product
    extra = 0
class CommentInline(admin.TabularInline):
    model = Comment
    extra = 0
class ItemInline(admin.TabularInline):
    model = Item
    extra = 0

class CartInline(admin.TabularInline):
    model = Cart
    extra = 0

class AddressInline(admin.TabularInline):
    model = Address
    extra =0

class OrderInline(admin.TabularInline):
    model = Order
    extra =0



@admin.register(User)
class UserAdmin(admin.ModelAdmin):
    list_display = ('username','email','mobile','email_active')
    inlines = [ItemInline,OrderInline,AddressInline,CommentInline]

@admin.register(Category)
class CatogoryAdmin(admin.ModelAdmin):
    list_display = ('id','name')
    fields = ['name',]
    inlines =[ProductInline]

@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    list_display = ('title','content',"product",'stars','customer','create_time','anonymity')
    fields = ['title','content',"product",'stars','customer','create_time','anonymity']


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('id','name','price','default_image_url','display_category','sales','skus_id','display_create_time','quantity')
    #display_category这里用不用都行，因为category中定义了__str__
    list_filter = ('category', )
    fieldsets = (
        ("General",{
            'fields':('name','price','category','default_image_url','skus_id')
        }),
        ('Advanced Option',{
            "classes": ["collapse"],
            'fields':('sales','quantity','create_time')
        }),
    )
    inlines =[CommentInline]


@admin.register(Cart)
class CartAdmin(admin.ModelAdmin):
    list_display = ('customer',)
    list_filter = ('customer',)
    inlines = [ItemInline]


@admin.register(Address)
class AddressAdmin(admin.ModelAdmin):
    list_display = ('customer','sender','send_address','reciever','recieve_address')
    list_filter = ('customer',)

@admin.register(Express)
class ExpressAdmin(admin.ModelAdmin):
    list_display = ('name',)

@admin.register(Pay)
class PayAdmin(admin.ModelAdmin):
    list_display = ('name',)

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ('customer','address','express','express_cost','total','pay_method')
    list_filter =('customer',)

    inlines = [ItemInline]